/*

	*********************************
				SF2D Engine
	*********************************

	Base Object Class
	By Julian Williams
	Jan 20, 2010
*/
#include <iostream>
#include <SFML/Graphics.hpp>

#include "app.h"
#include "image_manager.h"
#include "objects.h"


using namespace std;




Objects::Objects(void)
{
			velocity.x = 0;
			velocity.y = 0;

            speed = 0;
         
            h_direction = DIR_LEFT;
			v_direction = DIR_UP;

            state = 0;
			angle = 0;
}//EoF





//Check to see if on screen
bool Objects::Is_OnScreen()
{
	 if((GetPosition().x > 0) && (GetPosition().y > 0) && (GetPosition().x < App::getInstance().Get_RenderWindow()->GetWidth()) && (GetPosition().y < App::getInstance().Get_RenderWindow()->GetHeight()))
		 {
			return true;
		 }

	 return false;
}//EoF



/* Update Animation based off of Current Frame */
int Objects::Tile_Update()
{
 
 
  const int NumCols = GetImage()->GetWidth()/tile_size.x;
  const int NumRows = GetImage()->GetHeight()/tile_size.y;
  
  if ((NumCols < 1) || (NumRows < 1)) {return 2;} // surely this will never be true?
  // perhaps move it into an assertion instead?
  
  int tileCol = frame % NumCols;
  int tileRow = frame / NumCols;
    
  if (tileRow > (NumRows - 1)) {return 3;}
  if (tileCol < 0) {return 4;}

  const int srcx = tileCol*tile_size.x;
  const int srcy = tileRow*tile_size.y;

  //Set to the Specified Tile
  SetSubRect(sf::IntRect(srcx, srcy, srcx+tile_size.x, srcy+tile_size.y));

  return 0; 
}//EoF




//load image for sprite
bool Objects::Load_Image(std::string img_location)
{


	//Load teh image
	img = gImageManager.getResource( img_location );
	if(img == NULL) { return false; }


	SetImage(*img);

	return true;
}//EoF



